const {
	db,
	dbCmd,
	result_success,
	result_error,
	appletInfoCollection,
	shopieCollection,
	userCollection
} = require('../../common/constants')
module.exports = async function(params = {}) {
	const token = this.getUniIdToken()
	if (!token) {
		return result_error('登录失效,请重新登录')
	}
	let payload = await this.uniID.checkToken(token)
	if (payload.code) {
		return payload
	}
	let cUser = await userCollection.doc(payload.uid).get()
	cUser = cUser.data[0]
	if(!cUser.app_id){
		return result_success({})
	}
	//获取当前应用
	let appletInfoData = await appletInfoCollection.doc(cUser.app_id).get()
	appletInfoData = appletInfoData.data[0]
	let profitsharingData = await db.collection('wmzmall-profitsharing').where({
			app_id: appletInfoData._id
		})
		.skip(params.skip)
		.limit(params.limit)
		.orderBy('create_time', 'desc')
		.get()
	profitsharingData = profitsharingData.data
	return result_success(profitsharingData)
}